﻿using System;
using System.Collections.Generic;

namespace SmartParking.Web.Models
{
    public class ListModel
    {
        public string ViewTitle { get; private set; }
        public string ListTitle { get; private set; }
        public string ItemDetailView { get; private set; }
        public List<ListItemModel> Items = new List<ListItemModel>();
        public bool ReadOnly { get; private set; }
        public string EmptyMessage { get; private set; }

        public ListModel(OrderListModel model)
        {
            if (model == null) return;
            ViewTitle = model.ViewTitle;
            ListTitle = model.ListTitle;
            ItemDetailView = "Order";
            model.Orders.ForEach(item => Items.Add(new ListItemModel(item)));
            ReadOnly = model.ReadOnly;
            EmptyMessage = model.EmptyMessage;
        }

        public ListModel(ReservationListModel model)
        {
            if (model == null) return;
            ViewTitle = model.ViewTitle;
            ListTitle = model.ListTitle;
            var line = 0;
            model.Reservations.ForEach(item => Items.Add(new ListItemModel(ref line, item)));
            ReadOnly = model.ReadOnly;
            EmptyMessage = model.EmptyMessage;
        }

        public ListModel(CustomersModel model)
        {
            if (model == null) return;
            ListTitle = "Clientes";
            ItemDetailView = "Parkings";
            model.Customers.ForEach(item => Items.Add(new ListItemModel(item)));
            EmptyMessage = "No hay clientes";
        }
    }

    public class ListItemModel
    {
        public string Group;
        public string ItemId;
        public string Title;
        public string RightLine;
        public List<ListItemLineModel> Lines;

        public ListItemModel(OrderListItemModel model)
        {
            Group = model.Group;
            ItemId = model.Id;
            RightLine = model.Date;
            Lines = new List<ListItemLineModel>
                {
                    new ListItemLineModel("Monto", String.Format("¢{0}", model.Amount.Trim())),
                    new ListItemLineModel("Comisión", String.Format("¢{0}", model.Comission.Trim())),
                    new ListItemLineModel("Pago", model.PaymentType.Trim()),
                };
        }

        public ListItemModel(ref int id, ReservationListItemModel model)
        {
            Group = model.Group;
            ItemId = String.IsNullOrEmpty(model.Id) ? Convert.ToString(id++) : model.Id;
            RightLine = model.Date;
            Lines = new List<ListItemLineModel>
                {
                    new ListItemLineModel("Parqueo", model.ParkingName.Trim()),
                    new ListItemLineModel("Zona", model.ParkingZoneName.Trim()),
                    new ListItemLineModel("Reserva", String.Format("{0} a {1}", model.ReservationStartHour.Trim(), model.ReservationEndHour.Trim())),
                    new ListItemLineModel("Placa", model.CarPlate.Trim()),
                    new ListItemLineModel("Monto", String.Format("¢{0}", model.Amount.Trim())),
                    new ListItemLineModel("Comisión", String.Format("¢{0}", model.Comission.Trim()))
                };
            if (! String.IsNullOrEmpty(model.StartHour))
                Lines.Insert(2, new ListItemLineModel("Uso", String.Format("{0} a {1}", model.StartHour.Trim(), model.EndHour.Trim())));
        }

        public ListItemModel(CustomerModel model)
        {
            ItemId = Convert.ToString(model.CustomerID);
            Title = model.Name;
            Lines = new List<ListItemLineModel>
                {
                    new ListItemLineModel(content: model.Email.Trim(), bold: true),
                    new ListItemLineModel(content: model.Phone.Trim(), bold: true),
                    new ListItemLineModel(content: model.Address.Trim(), topic: false),
                };
        }
    }

    public class ListItemLineModel
    {
        public string Title;
        public string Content;
        public bool Bold;
        public bool Topic;

        public ListItemLineModel(string title = "", string content = "", bool bold = false, bool topic = true)
        {
            Title = title;
            Content = content;
            Bold = bold;
            Topic = topic;
        }
    }
}